<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户注册</title>

<style>
input[type=text], [type=password] {
	width: 235px;
	height: 30px;
	font-family: "微软雅黑";
	font-size: 14px;
	padding-left: 10px;
}

div {
	margin-bottom: 15px;;
}

input[type=submit] {
	width: 235px;
	height: 30px;
	color: white;
	font-family: "微软雅黑";
	font-size: 18px;
	background-color: #f56600;
	border: 0px solid;
	border-radius: 5px 5px 5px 5px;
}

input[type="submit"]:hover {
	cursor: pointer;
}

#registerDiv {
	margin-left: 500px;
	margin-top: 30px;
}

#h1 {
	margin-left: 600px;
	margin-top: 30px;
}
</style>

</head>
<body>

	<form action="" method="post">
		用户名:<input type="text" name="username" value="liu"/> <br/>
		
		密码：<input type="password" name="password" value="hao"/> <br/>
		
		性别：<input type="radio" name="oneradio" value="1">男
			 <input type="radio" name="oneradio" value="0">女<br/>
			 
		爱好：<input type="checkbox" value="10" name="onecheckbox">看书
			  <input type="checkbox" value="11" name="onecheckbox">看妹妹
			  <input type="checkbox" value="12" name="onecheckbox">看电影<br/>
		
		地址：<select name="oneselect">
				 <option value="1">广东</option>
				 <option value="2">茂名</option>
				 <option value="3">深圳</option>
				 <option value="4">湛江</option>
			</select><br/>
		
		<input type="hidden" name="hiddenmoney" value="1000$"><br/>
		
		<textarea rows="5" cols="5" name="introdution">我啊啦啦啦啦啦啦啦啦</textarea>><br/>
		<br/>
		<input  id="btn01" type="button" value="注册">
	</form>
	
	
</body>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.4.4.js" ></script>
<script type="text/javascript">
$(function(){
	
	$('#btn01').click(function(){
		
		var username=$('input[name="username"]').val();
		var password=$('input[name="password"]').val();

		var hobby='';
		var a= $('input[name="onecheckbox"]:checked').each(function(index,h){
			console.log(h.value);
			console.log($('input[name="onecheckbox"]:checked').length);
			var len=$('input[name="onecheckbox"]:checked').length;
			if(index==len-1){
				hobby=hobby+h.value;
				
			}else{
				hobby=hobby+h.value+",";
			}
		});
		
		var sex= $('input[name="oneradio"]:checked').val();
		
		var address=$('select option:selected').val();
		
		var hiddenmoney=$('input[type="hidden"]').val();
		
		var onetextarea=$('textarea[name="introdution"]').val();
		
		var url="${pageContext.request.contextPath}/check";
		
		var data={
				'username':username,
				'password':password,
				'hobby':hobby,
				'sex':sex,
				'address':address,
				'hiddenmoney':hiddenmoney,
				'introdution':onetextarea
				};
		
		$.post(url,data,function(data){
			console.log(data);
			var counter=data.counter;
			if(counter==1){
				//插入成功，跳转到成功页面
				window.location.href="${pageContext.request.contextPath}/user/success.jsp";
			}else{
				//插入成功，跳转到成功页面
			}
			
		},'json');
	
	});
	
});


</script>

</html>